/*
 * @Author: chenhuan 2218981866@qq.com
 * @Date: 2022-11-16 13:27:58
 * @LastEditors: chenhuan 2218981866@qq.com
 * @LastEditTime: 2022-11-21 18:49:06
 * @FilePath: \上课项目练习\111\react-menus-mangener\src\api\food.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from '../utils/request'

interface IFood {
  foodId: string,
  foodName: string,
  foodCategory: string,
  foodOrigincePrice: number,
  foodDiscount: number,
  foodTotal: number,
  foodSize: {
    large: number,
    middle: number,
    small: number,
  },
  foodHot: boolean,
  foodDesc: string,
  img1: string,
}
interface ISize {
  large: number,
  middle: number,
  small: number
}

interface ICategoryItem {
  label?: string,
  value?: string,
}
export interface IDetailProps {
  foodId: number,
  foodName: string,
  foodDesc: string,
  img1: string,
  foodOrigincePrice: number,
  foodCategory: string,
}
// 获取菜品的分类信息
export const getCategoryListApi = () => request.get<any, any>('/category')

// 新增菜品类别
export const postAddCategoryApi = (params: ICategoryItem) => request.post('/category', params)

// 删除分类
export const deleteCategoryApi = (id: number) => request.delete(`/category/${id}`)
// 查询分类列表
export const getCategoryItemApi = (categoryName: string) => request.get<any, string[]>(`/category?label=${categoryName}`)

// 获取所有菜品信息
export const getFoodNameListApi = () => request.get<any, IDetailProps[]>('/food')

// 查询商品类别信息
export const getCategoryFilterApi = (foodName: string, foodCategory:string) => request.get(`/food?foodName=${foodName}&foodCategory=${foodCategory}`)

// 获取菜品的 详细信息
export const getFoodDetailApi = (_page:number, _limit:number) => request.get<any, IDetailProps[]>(`/food?_page=${_page}&_limit=${_limit}`)

// 获取单个菜品的详细信息
export const getFoodItemDetailApi = (foodId: number) => request.get<any, IDetailProps[]>(`/food?foodId=${foodId}`)

// 修改菜品信息
export const patchFoodDetailApi = (id: string, params:IFood) => request.post<any, IDetailProps>(`/food/${id}`, params)

// 新增菜品
export const postAddFoodApi = (params: IFood) => request.post('/food', params)

// 删除菜品
export const deleteFoodApi = (id: string) => request.delete(`/food/${id}`)

// 查找某一个菜品
export const getIdFoodApi = (id: string) => request.get(`/food/${id}`)

// 修改菜品规格
export const patchUpdateFoodSizeApi = (id: string, params: ISize) => request.patch(`/food/${id}`, params)
